Module modErrors
    Public Sub errClientDisconnected(ByRef caller As Object, ByVal msg As protocol)
        errNetworkError(caller, msg)
    End Sub
    Public Sub errNetworkSendError(ByRef caller As Object, ByVal msg As Object)
        errNetworkError(caller, msg)
    End Sub

    Public Sub errNetworkReceiveError(ByRef caller As Object, ByVal msg As Object)
        errNetworkError(caller, msg)
    End Sub

    Public Sub errNetworkError(ByRef caller As Object, ByVal msg As Object)
        Dim clientIndex As Integer

        'close connection
        clientIndex = clients.getIndexByHash(Threading.Thread.CurrentThread.GetHashCode())
        If clientIndex = -1 Then
            'we are disconnecting an admin client
            clientIndex = admins.getIndexByHash(Threading.Thread.CurrentThread.GetHashCode())
            admins.clients(clientIndex).connection.Close()
            'remove client from client list
            admins.removeClient(clientIndex)
        Else
            'we are disconnecting an admin client
            clients.clients(clientIndex).connection.Close()
            'remove client from client list
            clients.removeClient(clientIndex)
        End If
        'abort thread
        Threading.Thread.CurrentThread.Abort()
    End Sub
End Module
